<template>
	<view class="shoppingCart">
		<view class="shoppingCart_listContent">
			<view v-for="(item,index) in List" @click="ChosensClick(item)" :class="Multiple(item)"
				class="shoppingCart_detail">
				<view class="shoppingCart_detail_Multiple">
					<view class="shoppingCart_detail_Multiple_radio"></view>
					<image class="shoppingCart_detail_Multiple_radio_Active" src="../../../static/home/radio.png"
						mode="widthFix"></image>
				</view>
				<view class="shoppingCart_detail_noMultiple">
					<view @click.stop="detail(item.goodsId)" class="shoppingCart_detail_left">
						<image :src="item.goodsImages" mode=""></image>
					</view>
					<view class="shoppingCart_detail_right">
						<view class="shoppingCart_detail_right_left">
							<view class="shoppingCart_detail_right_title">
								{{item.goodsName}}
							</view>
							<view class="shoppingCart_detail_right_bottom">
								<text>{{item.goodsSpecificationsNames}}</text>
							</view>
							<view class="shoppingCart_detail_right_left_price">
								<view class="shoppingCart_detail_right_left_price_left">
									平台VIP价
								</view>
								<view class="shoppingCart_detail_right_left_price_right">
									<view class="shoppingCart_detail_right_left_price_right_left">
										￥
									</view>
									<view class="shoppingCart_detail_right_left_price_right_right">
										{{item.goodsMemberPrice}}
									</view>
								</view>
							</view>
						</view>
					</view>

					<image @click.stop="deleteList(item.id , item.goodsName)"
						class="shoppingCart_detail_noMultiple_delete" src="../../../static/home/close.png" mode="">
					</image>
				</view>
			</view>
			<u-loadmore @loadmore="addmodle" :status="status" />
		</view>
		<view class="shoppingCart_buttonBox">
			<view class="shoppingCart_buttonBox_box">
				<view class="shoppingCart_buttonBox_boxNum">
					合计：<text class="shoppingCart_buttonBox_boxNum_left">￥</text><text v-if="user.isVip == 1"
						class="shoppingCart_buttonBox_boxNum_right">{{totalPriceMember()}}</text><text
						v-if="user.isVip == 0"
						class="shoppingCart_buttonBox_boxNum_right">{{totalPriceMemberNo()}}</text>
				</view>
				<view class="shoppingCart_buttonBox_buttonBox">
					<button :disabled="Chosens.length == 0" @click="confirmClick" class="shoppingCart_buttonBox_button">提交</button>
				</view>
			</view>
		</view>


		<u-modal :show="show" @confirm="confirm" @cancel="show = false" ref="uModal" @close="close" showCancelButton
			:closeOnClickOverlay="true">
			是否删除名为“{{deleteName}}”的商品吗？
		</u-modal>
	</view>
</template>

<script>
	import {
		bootshoppingCartselectpage,
		bootshoppingCartdelete
	} from '@/api/home'
	export default {
		data() {
			return {
				show: false,
				status: "loadmore",
				queryInquire: {
					pageSize: 10,
					pageNum: 1,
				},
				deleteID: '',
				deleteName: '',
				Chosens: [],
				loding: false,
				List: [],
				over: false,
				user: JSON.parse(uni.getStorageSync('user')),
				goosform: false
			}
		},
		created() {
			this.bootshoppingCartselectpage();
		},
		onReachBottom() {
			this.addmodle();
		},
		methods: {
			detail(id){
				uni.navigateTo({
					url: '/pages/index/detail/detail?id=' + id
				});
			},
			close() {
				this.show = false
			},
			confirm() {
				bootshoppingCartdelete(this.deleteID).then(res => {
					uni.showToast({
						title: res.message,
						duration: 2000,
						icon: 'none'
					});
					if (res.success == 1) {
						this.show = false
						this.queryInquire.pageNum = 1
						this.List = []
						this.over = false
						this.status = 'loadmore'
						this.addmodle();
					}
				})
			},
			confirmClick() {
				let arr = []
				for (var i = 0; i < this.Chosens.length; i++) {
					let elem = this.Chosens[i]
					arr.push(elem.id)
				}
				uni.navigateTo({
					url: '/pages/index/multipleplaceOrder/multipleplaceOrder?list='+JSON.stringify(arr)
				});
			},
			deleteList(id, name) {
				this.deleteID = id;
				this.deleteName = name;
				this.show = true

				// this.queryInquire.pageNum = 1
				// this.List = []
				// this.over = false
				// this.status = 'loadmore'
				// this.addmodle();

			},
			totalPriceMember() {
				let num = 0;
				for (var i = 0; i < this.Chosens.length; i++) {
					num += this.Chosens[i].goodsMemberPrice
				}
				return num
			},
			totalPriceMemberNo() {
				let num = 0;
				for (var i = 0; i < this.Chosens.length; i++) {
					num += this.Chosens[i].goodsPrice
				}
				return num
			},
			Multiple(row) {
				if (this.Chosens.indexOf(row) != -1) {
					return 'shoppingCart_detail_active'
				}
				return ''
			},
			ChosensClick(row) {
				if (this.Chosens.indexOf(row) == -1) {
					this.Chosens.push(row)
				} else {
					// this.Chosens.remove(row)
					let arr = []
					for (var i = 0; i < this.Chosens.length; i++) {
						let em = this.Chosens[i]
						if (em !== row) {
							arr.push(em)
						}
					}
					this.Chosens = arr

				}
			},
			addmodle() {
				if (this.over == true) {
					return;
				}
				if (this.status == "loadmore") {
					this.bootshoppingCartselectpage();
				}
			},

			bootshoppingCartselectpage() {
				this.status = "loading";
				bootshoppingCartselectpage(this.queryInquire)
					.then((res) => {
						if (res.success == 1) {
							this.List = this.List.concat(res.data.records);
							if (res.data.current == res.data.pages) {
								this.over = true;
								setTimeout(() => {
									this.status = "nomore";
								}, 0);
							} else {
								this.queryInquire.pageNum++;
							}
						}
					})
					.finally(() => {
						this.status = "loadmore";
					});
			},
		}
	}
</script>
<style scoped lang="scss">
	* {
		box-sizing: border-box;
	}

	.shoppingCart {
		.shoppingCart_listContent {
			padding: 32upx;

			.shoppingCart_detail {
				display: flex;
				border-radius: 12upx;
				background-color: #ffffff;
				padding: 24upx;
				align-items: center;
				padding-right: 62upx;
				margin-top: 20upx;
				position: relative;

				.shoppingCart_detail_Multiple {
					padding-left: 12upx;

					.shoppingCart_detail_Multiple_radio_Active {
						width: 36upx;
						height: 36upx;
						display: none;
					}

					.shoppingCart_detail_Multiple_radio {
						width: 36upx;
						height: 36upx;
						border: 2upx solid rgba(0, 0, 0, 0.3);
						border-radius: 1000%;
					}
				}

				.shoppingCart_detail_noMultiple {
					display: flex;
					width: calc(100% - 36upx - 12upx - 30upx);
					margin-left: 30upx;

					.shoppingCart_detail_left {
						width: 200upx;
						height: 200upx;

						image {
							width: 100%;
							border-radius: 10upx;
							height: 100%;
						}
					}

					.shoppingCart_detail_right {
						width: calc(100% - 200upx - 40upx);
						margin-left: 40upx;
						display: flex;

						.shoppingCart_detail_right_left {
							width: calc(100%);

							.shoppingCart_detail_right_title {
								text-overflow: -o-ellipsis-lastline;
								overflow: hidden;
								text-overflow: ellipsis;
								display: -webkit-box;
								-webkit-line-clamp: 1;
								line-clamp: 1;
								-webkit-box-orient: vertical;

								font-size: 28upx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: rgba(0, 0, 0, 0.89);
								line-height: 40upx;
							}

							.shoppingCart_detail_right_bottom {
								padding: 16upx;
								background-color: #f5f5f5;
								margin-top: 6upx;
								font-size: 24upx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: rgba(0, 0, 0, 0.5);
								line-height: 34upx;

								text-overflow: -o-ellipsis-lastline;
								overflow: hidden;
								text-overflow: ellipsis;
								display: -webkit-box;
								-webkit-line-clamp: 2;
								line-clamp: 2;
								-webkit-box-orient: vertical;
							}

							.shoppingCart_detail_right_left_price {
								display: flex;
								align-items: center;
								margin-top: 16upx;

								.shoppingCart_detail_right_left_price_left {
									font-size: 22upx;
									font-family: PingFangSC-Regular, PingFang SC;
									font-weight: 400;
									color: rgba(0, 0, 0, 0.9);
									line-height: 32upx;
								}

								.shoppingCart_detail_right_left_price_right {
									display: flex;
									align-items: center;
									color: #ED2525;

									.shoppingCart_detail_right_left_price_right_left {
										font-size: 34upx;
									}

									.shoppingCart_detail_right_left_price_right_right {
										font-size: 36upx;
										font-family: PingFangSC-Semibold, PingFang SC;
										font-weight: 600;
										color: #ED2525;
										line-height: 50upx;
									}
								}
							}
						}

					}

					.shoppingCart_detail_noMultiple_delete {
						width: 25upx;
						height: 25upx;
						position: absolute;
						right: 14upx;
						top: 24upx;
					}
				}
			}

			.shoppingCart_detail_active {
				.shoppingCart_detail_Multiple_radio {
					display: none;
				}

				.shoppingCart_detail_Multiple_radio_Active {
					display: block !important;
				}
			}

		}

		.shoppingCart_buttonBox {
			position: fixed;
			bottom: 0;
			padding: 20upx;
			height: 170upx;
			width: 100%;
			left: 0;
			display: flex;
			justify-content: flex-end;
			background-color: #fff;
			align-items: center;

			.shoppingCart_buttonBox_box {
				display: flex;
				align-items: center;

				.shoppingCart_buttonBox_box_left {
					color: #ccc;
					font-size: 34upx;
				}

				.shoppingCart_buttonBox_boxNum {
					font-size: 34upx;

					display: flex;
					align-items: center;

					.shoppingCart_buttonBox_boxNum_left {
						font-size: 34upx;
						color: #ED2525;
					}

					.shoppingCart_buttonBox_boxNum_right {
						font-size: 50upx;
						color: #ED2525;
					}

				}

				.shoppingCart_buttonBox_buttonBox {
					margin-left: 32upx;

					.shoppingCart_buttonBox_button {
						background-color: #ED2525;
						color: #ffffff;
						border-radius: 174upx;
						width: 174upx;
						height: 74upx;
						line-height: 74upx;

						&::after {
							display: none;
						}

						&[disabled] {
							background-color: #D8D8D8;
							color: #000000;
						}
					}
				}
			}
		}
	}
</style>
<style>
	page {
		background-color: #E5E7E9;
	}
</style>
